﻿using IBLL;
using IDAL;
using Model;

namespace BLL
{
    public class quanbuBLL : iquanbuBLL
    {
        public quanbuBLL(IbaseDAL<yonghuModel> dal, IbaseDAL<xueshengModel> dal2)
        {
            Dal = dal;
            Dal2 = dal2;
        }

        public IbaseDAL<yonghuModel> Dal { get; }
        public IbaseDAL<xueshengModel> Dal2 { get; }

        public yonghuModel denglu(string name, string mima)
        {
            var rph = Dal.GetAll().FirstOrDefault(a => a.name == name);
            if (rph == null)
            {
                rph = new yonghuModel() { id = -1 };
            }
            else if (rph.mima != mima)
            {
                rph = new yonghuModel() { id = -2 };
            }
            return rph;
        }

        public dynamic xianshi(int pageindex, int pagesize)
        {
            var xuesheng = Dal2.GetAll();
            var prh = from a in xuesheng
                      select new
                      {
                          a.email,
                          a.phone,
                          a.banjihao,
                          a.Id,
                          a.Name

                      };

            var count=prh.Count();

            var list=prh.OrderBy(a=>a.Id).Skip((pageindex-1)*pagesize).Take(pagesize).ToList();

            return new
            {
                count=count,
                list=list
            };
        }
    }
}
